<script setup lang="ts">
import {getUrlParams, throttle} from "@/utils";
import { getSolutionListServer} from "@/api/solution";
import seo from "@/utils/seo";
import {getSeoInfoServer, getWebBanner} from "@/api/common";
const currentTabIndex = ref(0)
const solutionData = ref([])
const scroll = ref()

const instance = getCurrentInstance();

const seoInfo = ref({...seo,title:'数据安全 防泄漏智能加密系统_文档安全 加密软件_华途解决方案'})
const getSeo = async ()=>{
  const {data} =await getSeoInfoServer("/solution")
  seoInfo.value = {...data}
}
getSeo()

const setTabHandle = (index: number) => {
  currentTabIndex.value = index
  scrollTo(index)
}
const scrollTo = (currentIndex: any) => {
  const pageHeight = document.body.clientHeight;
  let R = 0.15 + currentIndex * 0.0892
  document.documentElement.style.scrollBehavior = 'smooth';
  window.scroll(0, pageHeight * R);
}
const getSolutionData = async () => {
  const {data} = await getSolutionListServer()
  solutionData.value = data
  let type = getUrlParams('type')
  if (type) {
    let index = getIdByType(type)
    if (index >= 0) {
      setTimeout(() => {
        currentTabIndex.value = index
        scrollTo(index)
      }, 10)
    }
  }
  setTimeout(() => {
    window.addEventListener('scroll', T);
  }, 100)
}
const getIdByType = (type: any) => {
  return solutionData.value.findIndex(item => (item.id == type))
}
const BannerInfo = ref({
  imageOrVideo: '',
  intro: '',
  title: '',
  caseIntroList: '',
})
const getBanner = async () => {
  const {data} = await getWebBanner(5)
  if (data) {
    BannerInfo.value = data
  }
}
const loadScroll = () => {
  let cards = document.querySelectorAll('.ht-solution-card-item');
  if (!cards.length) return;

  let DPR = window.devicePixelRatio;
  const R = 170 / DPR;

  let currentTabIndexValue = 0; // 默认值为0，表示至少匹配到第一个卡片

  for (let i = 0; i < cards.length; i++) {
    const top = cards[i].getBoundingClientRect().top;
    const nextTop = i < cards.length - 1 ? cards[i + 1].getBoundingClientRect().top : Infinity;

    if (top < R && nextTop > R) {
      currentTabIndexValue = i;
      break;
    }
  }

  currentTabIndex.value = currentTabIndexValue;
}
let T = throttle(loadScroll, 100)
onActivated(() => {
});
  getSolutionData()
  getBanner()

onDeactivated(() => {
  window.removeEventListener('scroll', T);
});
</script>
<template>
  <div class="ht-solution">
    <Head>
      <Title>{{ seoInfo.title}}</Title>
      <Meta name="description" :content="seoInfo.description"/>
      <Meta name="keywords" :content="seoInfo.keyword"/>
    </Head>
    <div class="ht-solution-top">
      <div class="banner-container">
        <BannerMedia  :url="BannerInfo.imageOrVideo"/>
      </div>
      <div class="top-title">{{BannerInfo.title}}</div>
      <div class="top-subtitle">{{BannerInfo.intro}}</div>
    </div>
    <div class="ht-solution-main">
      <aside ref="scroll" :style="{height:`${solutionData.length}rem`}">
        <div class="tabs-nav-scroll">
          <div class="tab-list">
            <div class="active-bar" :style="{transform:'translateY('+0.95*(currentTabIndex)+'rem)'}"></div>
            <div class="tab-list-item" :class="currentTabIndex===index?'active':''" v-for="(item,index) in solutionData"
                 :key="index" @click="setTabHandle(index)">
              {{ item.title }}
            </div>
          </div>
        </div>
      </aside>
      <main>
        <div class="ht-solution-card-item" v-for="(item) in solutionData" :key="item.id">
          <div class="card-item-txt">
            <div class="card-title">{{ item.title }}</div>
            <div class="card-desc">
              {{ item.schemeOverview }}
            </div>
            <NuxtLink :to="`/solution/${item.id}`" class="view-detail">
              <LearnMore label="查看详情"/>
            </NuxtLink>
          </div>
          <div class="card-item-image">
            <img :src="item.listCoverImage" alt="">
<!--            <div class="musk"></div>-->
          </div>
        </div>
      </main>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.ht-solution {
  &-top {
    width: 24rem;
    height: 10.5rem;
    //background: url(~/assets/images/solution/solution-top-bg.jpg) no-repeat;
    //background-size: 24rem 10.5rem;
    text-align: center;
    color: #FFFFFF;
    padding-top: 0.1px;
    position: relative;
    .banner-container {
      z-index: -1;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
    }


    .top-title {
      margin-top: 4.38rem;
      font-size: 0.8rem;
      font-weight: bold;
    }

    .top-subtitle {
      margin-top: 0.06rem;
      font-size: 0.33rem;
      font-weight: 400;
    }
  }

  &-main {
    background: #fff;
    position: relative;
    transition: transform .3s;
    padding-left: 1.05rem;
    padding-right: 1.35rem;
    padding-top: 1.96rem;
    margin-bottom: 2rem;
    display: flex;

    aside {
      position: sticky;
      width: 5.15rem;
      height: 6rem;
      display: inline-block;
      top: 1.36rem;
      overflow-y: scroll;

      &::-webkit-scrollbar {
        display: none;
      }

      &:after {
        content: "";
        position: absolute;
        left: 0;
        right: auto;
        bottom: 0;
        width: 2px;
        height: 100%;
        background-color: #e4e7ed;
        z-index: 1;
      }

      .tabs-nav-scroll {
        .tab-list {
          padding-left: 0.44rem;
          position: relative;

          .active-bar {
            transform: translateY(0px);
            height: 0.95rem;
            position: absolute;
            left: 0;
            right: auto;
            background-color: #3ab5ec;
            transition: transform .3s cubic-bezier(.645, .045, .355, 1);
            list-style: none;
            top: 0;
            bottom: auto;
            width: 3px;
            z-index: 2;
          }

          &-item {
            cursor: pointer;
            height: 0.95rem;
            display: flex;
            align-items: center;
            font-size: 0.25rem;
            font-weight: 500;
            color: #666666;
            width: 2.2rem;

            &.active {
              font-weight: bold;
              color: #111111;
            }
          }
        }
      }


    }

    main {
      .ht-solution-card-item {
        display: flex;
        width: 16.46rem;
        height: 5.45rem;
        border-radius: 0.25rem;
        border: 0.01rem solid #E0EEFF;
        padding-top: 0.1px;
        justify-content: space-between;
        margin-bottom: 1.06rem;
        transition: 0.3s;

        &:last-child {
          margin-bottom: 0;
        }

        &:hover {
          background: linear-gradient(269deg, #FFFFFF 0%, #F8FAFF 100%);
          box-shadow: 0rem 0.19rem 0.63rem 0.01rem rgba(46, 106, 255, 0.1);
          border-color: transparent;

          ::v-deep(.view-detail) {
            .cp-learn-more {
              color: #fff;
              background: linear-gradient(61deg, #47FFDA 0%, #2E6AFF 100%);
              border: none;

              .white {
                display: inline-block;
              }

              .black {
                display: none;
              }
            }

          }
        }

        &:nth-child(odd) {
          .card-item-txt {
            margin-left: 0.88rem;
            margin-top: 1.15rem;

            .card-title {
              font-size: 0.5rem;
              font-weight: bold;
              color: #111111;
            }

            .card-desc {
              margin-top: 0.24rem;
              width: 7.19rem;
              height: 1.1rem;
              font-size: 0.23rem;
              font-weight: 400;
              color: #999999;
              line-height: 0.38rem;
              text-overflow: ellipsis; // 超出用省略号显示
              overflow: hidden; // 超出的文本隐藏
              display: -webkit-box; // 作为弹性伸缩盒子模型显示
              -webkit-line-clamp: 3; // 显示的行
              -webkit-box-orient: vertical;
            }

            .view-detail {
              display: inline-block;
              margin-top: 0.75rem;
            }
          }

          .card-item-image {
            position: relative;
            overflow: hidden;

            .musk {
              pointer-events: none;
              position: absolute;
              left: 0;
              top: 0;
              width: 7.69rem;
              height: 5.45rem;
              background: linear-gradient(269deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 100%);
              z-index: 2;
            }

            img {
              object-position: bottom;
              object-fit: cover;
              width: 8.05rem;
              height: 5.45rem;
              background: #FFFFFF;
              border-radius: 0.25rem 0.25rem 0.25rem 0.25rem;
            }
          }
        }

        &:nth-child(even) {
          flex-direction: row-reverse;
          justify-content: left;

          .card-item-txt {
            margin-top: 1.15rem;
            margin-left: 0.3rem;

            .card-title {
              font-size: 0.5rem;
              font-weight: bold;
              color: #111111;
            }

            .card-desc {
              margin-top: 0.24rem;
              height: 1.1rem;
              width: 7.19rem;
              font-size: 0.23rem;
              font-weight: 400;
              color: #999999;
              line-height: 0.38rem;
              text-overflow: ellipsis; // 超出用省略号显示
              overflow: hidden; // 超出的文本隐藏
              display: -webkit-box; // 作为弹性伸缩盒子模型显示
              -webkit-line-clamp: 3; // 显示的行
              -webkit-box-orient: vertical;
            }

            .view-detail {
              display: inline-block;
              margin-top: 0.75rem;
            }
          }

          .card-item-image {
            position: relative;
            overflow: hidden;

            .musk {
              pointer-events: none;
              position: absolute;
              right: 0;
              top: 0;
              width: 7.69rem;
              height: 5.45rem;
              background: linear-gradient(91deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 100%);
              z-index: 2;
            }

            img {
              width: 8.05rem;
              height: 5.45rem;
              background: #FFFFFF;
              border-radius: 0.25rem 0.25rem 0.25rem 0.25rem;
            }
          }
        }
      }
    }
  }
}
</style>
